<?php
 session_start();
 include("include/session.php");
 include("include/common.php");
 include("include/db.php");
 
 if($_REQUEST['course_category'] != ''){
	$courseCode = $_REQUEST['course_category'].'-'.date("ymdHi");	 
 }
 

 
 if(isset($_REQUEST) && $_REQUEST['submit'] != ''){
 	
	
	
	$course_category	= mysql_real_escape_string($_REQUEST['course_category']); 
	$course_code		= mysql_real_escape_string($_REQUEST['course_code']);
	$start_date 		= mysql_real_escape_string($_REQUEST['start_date']);
	$end_date 			= mysql_real_escape_string($_REQUEST['end_date']);
	$number_classes 	= mysql_real_escape_string($_REQUEST['number_classes']);
	$comments 			= mysql_real_escape_string($_REQUEST['comments']);
	$active 			= mysql_real_escape_string($_REQUEST['active']);
	
	
	$sqlCategory = "INSERT INTO software_courses
								 SET 
							name					=	'$course_code',
							start_date				=	'$start_date',
							end_date				=	'$end_date',
							number_classes			=	'$number_classes',
							batch_code				=	'$course_code',
							category				=	'$course_category',
							comments				=	'$comments',
							active					=   '$active'
							"
							; 	
	if(mysql_query($sqlCategory))
		header("location:addcourses.php?msg=1");
	else
		header("location:addcourses.php?msg=2");
	exit();		
 }

 ?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title><?=TITLE_WEBSITE?></title>
<link href="css/c_energy.css" rel="stylesheet" type="text/css" />
<link href="css/logo.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="css/datepicker.css" type="text/css" />
<link rel="stylesheet" media="screen" type="text/css" href="css/layout.css" />
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/datepicker.js"></script>
<script type="text/javascript" src="js/eye.js"></script>
<script type="text/javascript" src="js/utils.js"></script>
<script type="text/javascript">
</script>
<style type="text/css">
<!--
.style4 {
	font-size: 22px;
	font-weight: bold;
}
.style6 {color: #999999}
-->
</style>
</head>
<script>

function validation(){
	
	var message = '';
	
	
	if(document.getElementById("course_category").value == ""){
		message += 'Please enter course category\n';
	}
	if(document.getElementById("number_classes").value == ""){
		message += 'Please enter course classess\n';
	}
	
	if(message != ""){
		alert(message);
		return false;
	}
	
	
}
</script>
<body>

    <table width="990" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
        <td colspan="3" align="left" valign="top" ><? require("header.php");?></td>
</tr>
  <tr>
    <td align="center" >
	<table width="99%" cellspacing="0" cellpadding="0">
      <tr>
        <td colspan="3" align="center" valign="top">&nbsp;</td>
      </tr>
       <tr bgcolor="#FAFAFA">
        <td colspan="0" align="left" valign="top" >
		   <table width="96%" cellspacing="0" cellpadding="0">
		    <tr>
		      <td width="2%" align="left" valign="top" style="padding-left:15px" ><? require("left.php");?></td>
		      <td width="94%"  valign="top" style="padding-left:15px" >
			  <form name="signform" action="" method="post" enctype="multipart/form-data" id="signform" onsubmit="return validation();" >
			    <table id="signInTbl" width="719" cellspacing="0" cellpadding="0" style="border:solid #cccccc 1px">
                  <tr>
                    <td colspan="2" align="left" bgcolor="#373737" class="loc_search_found_term"  style="border-bottom:solid #cccccc 1px">Add Courses</td>
                  </tr>
                  <?php
                  	if($_REQUEST['msg'] == 1)
					{
				  ?>
                  <tr style="background: #D5FFD5 " height="25">
                 	<td colspan="2"><div align="left" class="successMsg" id="err_site" style="display:block">
                       &nbsp; <strong><?=($_REQUEST['msg'] == 1 ? 'Course inserted successfully' : 'Sorry,record does not inserted.')?></strong>
                    </div></td>
                  </tr>
                  <?php
                  	}elseif($_REQUEST['msg'] == 2){
				  ?>
                  <tr style="background: #FFE9E9 " height="25">
                 	<td colspan="2"><div align="left" class="ErrorMsg" id="err_site" style="display:block">
                       &nbsp; <strong><?=($_REQUEST['msg'] == 1 ? 'Course inserted successfully' : 'Sorry,record does not inserted.')?></strong>
                    </div></td>
                  </tr>	
				  <?php		
					}
				  ?>

                <tr height="30">
                    <td width="249" align="left" style="padding-left:15px">User Course</td>
                    <td width="466" align="left">
                    	<select id="course_category" name="course_category" style="width:220px" onchange="window.location.href='addcourses.php?course_category='+this.value" >
                        	<option value="" selected="selected" >Select</option>
                           <?php
                           	$sqlCourse = mysql_query("SELECT * FROM software_main_course where active = 'Y'");
							while($resCourse = mysql_fetch_array($sqlCourse)){
						   ?>
                           	<option value="<?php echo $resCourse["course_name"]?>" <?=($resCourse["course_name"] == $_REQUEST['course_category'] ? 'selected=selected' : '')?>> <?php echo $resCourse["course_name"]?></option>
                           
						   <?php			
							}
						   ?>
                        </select>
                    </td>
                </tr> 
                 <tr height="30">
                    <td width="249" align="left" style="padding-left:15px">Course Code</td>
                    <td width="466" align="left">
                      <input  style="width:220px" readonly="readonly" name="course_code" id="course_code" type="text" class="Box" maxlength="35"  value="<?=$courseCode?>"  />                    </td>
                </tr>
                <tr height="30">
                    <td width="249" align="left" style="padding-left:15px"> Course Start Date</td>
                    <td width="466" align="left">
                      <input style="width:190px"  id="start_date" name="start_date" value="<?=date("Y-m-d H:i")?>" type="text"    maxlength="25" /><img src="images/Calendar.gif" align="absmiddle" style="cursor:pointer;  margin-left:3px; margin-top:2px;" onclick="return showCalendar('start_date', '%Y-%m-%d %H:%M', '24', true);" /></td>
                </tr>
				<tr height="30">
                    <td width="249" align="left" style="padding-left:15px">Course End Date</td>
                    <td width="466" align="left">
                      <input style="width:190px"    name="end_date" id="end_date" type="text"   maxlength="25" value="<?=date("Y-m-d H:i")?>" /><img src="images/Calendar.gif" align="absmiddle" style="cursor:pointer;  margin-left:3px; margin-top:2px;" onclick="return showCalendar('end_date', '%Y-%m-%d %H:%M', '24', true);" />                    </td>                  </tr>
                
                   <tr height="30">
                    <td width="249" align="left" style="padding-left:15px">Number of classes</td>
                    <td width="466" align="left">
                    <select id="number_classes" name="number_classes"  style="width:220px" >
					<option value="" >Select</option>
					<?php
                    for($i=1;$i<=50;$i++){
					?>
                    <option value="<?php echo $i?>" ><?php echo $i?></option>
                    <?php
					}
					?>
                    </select>
                    </td>
                  </tr>
              	<tr height="30">
                    <td width="249" align="left" style="padding-left:15px">Course Comments</td>
                    <td width="466" align="left">
                      <input  style="width:220px" name="comments" id="comments" type="text" class="Box" value="<?=$_REQUEST['comments']?>" maxlength="70" />                    </td>
                  </tr>
                  <tr  height="30">
                    <td width="249" align="left" style="padding-left:15px">Active</td>
                    <td width="466" align="left">
                    	<select id="active" name="active" style="width:220px" >
                        	<option value="" >Select</option>
                            <option value="N" >Non-Active</option>
                            <option value="Y" >Active</option>
                        </select>                    </td>
                  </tr>
                   <tr  height="30">
                    <td width="249"  style="padding-left:15px" colspan="2" align="center"><input class="cls_button" type="submit" id="submit" name="submit" value="Submit"  /></td>
                  </tr>
                </table>
			    <ul class="site_nav_menu_buttons">
			      <li class="no_menu_li"><span><a href="courses.php">&nbsp;Back to Courses </a></span></li>
			      </ul>
			    <p>&nbsp;</p>
			  </form>			  </td>
            </tr>
	        </table></td>
        </tr>
      <tr bgcolor="#FAFAFA">
        <td width="800" align="center" valign="top">&nbsp;</td>
        <td width="100" colspan="2">&nbsp;</td>
      </tr>
	    <tr bgcolor="#FAFAFA">
        <td width="800" align="center" valign="top">&nbsp;</td>
        <td colspan="2">&nbsp;</td>
      </tr>
    </table></td>
  </tr>
</table>
</body>
</html>

